<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp" %>
<title>添加记录</title>
</head>
<body>

<fieldset class="layui-elem-field" style='margin:20px;padding:20px'>
  <legend>信息维护</legend>
  <div class="layui-field-box">
   	<form class="layui-form layui-form-pane" action="">
   	  <div class="layui-form-item">
	    <label class="layui-form-label">员工编号</label>
	    <div class="layui-input-inline">
	      <!-- <input type="text" name="empCode" required  lay-verify="required"
	        placeholder="请输入员工编号" autocomplete="off" class="layui-input"> -->
	        <select name="empCode" required lay-verify="required"></select>
	    </div>
	   </div>
	   <div class="layui-form-item">
	    <label class="layui-form-label">项目编号</label>
	    <div class="layui-input-inline">
	      <!-- <input type="text" name="proCode" required lay-verify="required"  
	        placeholder="请输入项目编号" autocomplete="off" class="layui-input"> -->
	      <select name="proCode" required lay-verify="required"></select>
	    </div>
	   </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">绩效</label>
	    <div class="layui-input-inline">
	      <input type="text" name="score" required  lay-verify="required" 
	      placeholder="请输入绩效" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <div class="layui-input-inline">
		  <input type="button" class="layui-btn" lay-submit lay-filter="add" value="确定">		   
	      <input type="reset" class="layui-btn layui-btn-primary" value="重置">
	    </div>
	    <input type="button" class="layui-btn" value="关闭" onclick="toClose()">
	  </div>
	  <input type="hidden" name="action" value="add"  />
	</form>
  </div>
</fieldset>

<script type="text/javascript">
// function toClose(){//当你在iframe页面关闭自身时
// 	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
// 	parent.layer.close(index); //再执行关闭   
// }

//初始化下拉框数据
initSelect();
function initSelect(){
	ajax("/employee",{action:'sel'},'json',function(data){
		console.log(data)
		var html='<option value=""></option>'
		$.each(data,function(index,element){
			html+='<option value="'+this.code+'">'+this.name+'</option>'
		})
		$("select[name='empCode']").html(html);
		form.render();//渲染，动态改变页面
	})
	ajax("/project",{action:'sel'},'json',function(data){
		console.log(data)
		var html='<option value=""></option>'
		$.each(data,function(index,element){
			html+='<option value="'+this.code+'">'+this.name+'</option>'
		})
		$("select[name='proCode']").html(html);
		form.render();//渲染，动态改变页面
	})
}

formOn("/score",'submit(add)',"text",function(data){
	console.log(data)
	if("E"==data){
		layer.msg("编号已存在")
	}else if("1"==data){
		layer.msg("添加成功",toClose)
	}else{
		layer.msg("添加失败");
	}
})
</script>
</body>
</html>